package com.kiven.thread;

import java.lang.Runnable;

public class ThreadDemo6 implements Runnable {
	
	/*
	 * yield() 与 sleep() 两个方法之间的区别
	 * 
	 */
	
	@Override
	public void run() {
		for (int i = 0; i < 10; i++) {
			if(i == 5 && Thread.currentThread().getName().equals("t1")) {
				Thread.yield();
			}
			
			System.out.println(Thread.currentThread().getName() + ": " + i);
		}
	}

	public static void main(String[] args) throws Exception {
		Runnable r1 = new ThreadDemo6();

		Thread t1 = new Thread(r1, "t1");
		Thread t2 = new Thread(r1, "t2");

		t2.setPriority(Thread.MAX_PRIORITY);
		t1.setPriority(Thread.MIN_PRIORITY);
		
		t1.start();
		t2.start();
	}

}
